<script setup>
import { ref, reactive, toRaw } from 'vue'
import { service, cache } from '@utils'
import { ElMessage } from 'element-plus'

const emit = defineEmits(['refresh'])

const visible = ref(false)
const formRef = ref()
const data = ref()

const state = reactive({
    param: {}
})

const open = (item) => {
    data.value = item
    visible.value = true
}

const close = () => {
    visible.value = false
    data.value = null
    state.param = {}
}

const sure = async () => {
    realSubmit()
}
const realSubmit = async () => {
    const { remitRemark } = toRaw(state.param)
    const res = await service.fund.withdrawRemit({
        remark:remitRemark,
        withdrawRecordId: data.value.withdrawRecordId,
        status:4
    })
    if (res) {
        ElMessage.success('打款成功')
        close()
        emit('refresh')
    }
}
//把方法暴露给父组件
defineExpose({
    open
})
</script>
    <template>
    <el-dialog v-model="visible" title="打款" center :close-on-click-modal="false" @close="close" destroy-on-close :width="500">
        <section v-if="data">
            <el-form :model="state.param" ref="formRef" label-width="100px" label-suffix=":" onsubmit="return false;">
                <el-form-item label="提现金额">{{data.withdrawAmount}}</el-form-item>
                <el-form-item label="收款人">{{data.payeeName}}</el-form-item>
                <el-form-item label="收款账户">{{data.payeeAccountNo}}</el-form-item>
                <el-form-item label="收款类型">{{data.payeeAccountType == 1 ?'支付宝':'其他'}}</el-form-item>
                <el-form-item label="备注" prop="remitRemark">
                    <el-input v-model="state.param.remitRemark" type="textarea" placeholder="请输入备注" :rows="3" :maxlength="150"
                        show-word-limit clearable></el-input>
                </el-form-item>
            </el-form>
        </section>

        <template #footer>
            <span class="flex-align-end">
                <div class="margin-right20">
                    <el-button @click="close">取消</el-button>
                </div>
                <el-button type="primary" @click="sure">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>
        